﻿/*
 * ========================================================================
 * Copyright(c) 2007-2012 情留メ蚊子, All Rights Reserved.
 * Welcom use the LiteFetion.
 * See more information,Please goto http://www.94qing.com
 * ========================================================================
 * 
 * 作 者：情留メ蚊子
 * Q  Q: 540644769
 * 邮 箱：qlwz@qq.com
 * 网 址：http://www.94qing.com
 * ========================================================================
*/
using System;
using LiteFetion.Model;
using Newtonsoft.Json.Linq;

namespace LiteFetion.Notify
{
    /// <summary>
    /// 好友消息
    /// </summary>
    public class BuddyMessageNotify
    {
        public BuddyMessageNotify(FetionClient client, JObject data)
        {
            this.FetionClient = client;
            int fromUserId = data.Value<int>("fromUid");
            this.Message = data.Value<string>("msg");
            int msgType = data.Value<int>("msgType");
            this.SendDate = data.Value<string>("sTime").ToDateTime().AddHours(8);//不知道为什么与服务器相差8小时
            this.Buddy = this.FetionClient.BuddyManager.GetBuddyByUserId(fromUserId);
            if (msgType == 2)
            {
                //接收到消息
            }
            else if (msgType == 3 || msgType == 4)
            {
                //发送消息失败，暂不处理..
            }
            Event.OnBuddyMessageNotify(this);
        }

        /// <summary>
        /// FetionClient
        /// </summary>
        public FetionClient FetionClient { get; private set; }

        /// <summary>
        /// 好友对象
        /// </summary>
        public Buddy Buddy { get; private set; }

        /// <summary>
        /// 消息内容
        /// </summary>
        public string Message { get; private set; }

        /// <summary>
        /// 发送时间
        /// </summary>
        public DateTime SendDate { get; private set; }

        public override string ToString()
        {
            return "BuddyMessageNotify [Buddy=" + this.Buddy.DisplayName + ", Message=" + this.Message
                + ", SendDate=" + this.SendDate + "]";
        }
    }
}
